package com.wang.luntan.users.pojo;

import com.wang.luntan.common.pojo.BasePojo;
import lombok.Data;

import java.util.Date;
import java.util.Map;
import java.util.TreeMap;

@Data
public class AtAdmins extends BasePojo<AtAdmins> {
    //主键id
    private int id;
    //邮箱
    private String email;
    //密码
    private String password;
    //名称
    private String name;
    //QQ
    private String qq;
    //联系方式
    private String phone;
    //登陆次数
    private int loginCount;
    //登陆失败次数
    private int failedCount;
    //登陆失败时间
    private Date failedTime;
    //性别:0-无 1-男 2-女
    private byte sex;
    //自我介绍
    private String content;
    //状态:0-禁用 1-启用
    private byte status;
    //创建时间
    private Date createTime;
    //更新时间
    private Date updateTime;
    //上次登陆时间
    private Date lastLoginTime;
    private Date pubTime;

    private String statusStr;
    private String sexStr;

    /* 用户的token */
    private String tokenStr;

    /*
     * 方便枚举项在网页上显示出来 键为值(数字), 值为字符串描述 只提供get方法
     */
    private Map<String, String> enumsMap = new TreeMap<String, String>();

    public Map<String, String> getEnumsMap() {
        // 根据状态值获取字符串描述
        AtAdminsEnum[] adminsEnums = AtAdminsEnum.values();
        for (int i = 0; i < adminsEnums.length; i++) {
            AtAdminsEnum adminsEnum = adminsEnums[i];
            String key = adminsEnum.toString();
            enumsMap.put(key + "-" + adminsEnum.getStatus() + "", adminsEnum.getName());
        }
        return enumsMap;
    }

    public String getStatusStr_Source() {
        if (this.status == 0) {
            this.statusStr = "禁用";
        } else if (this.status == 1) {
            this.statusStr = "启用";
        }
        return statusStr;
    }

    public String getStatusStr() {
        AtAdminsEnum[] values = AtAdminsEnum.values();
        for (int i = 0; i < values.length; i++) {
            AtAdminsEnum adminsEnumTemp = values[i];
            if (adminsEnumTemp.toString().startsWith("STATUS")) {
                if (adminsEnumTemp.getStatus() == this.status) {
                    this.statusStr = adminsEnumTemp.getName();
                }
            }
        }

        return statusStr;
    }

    public String getSexStr() {
        AtAdminsEnum[] values = AtAdminsEnum.values();
        for (int i = 0; i < values.length; i++) {
            AtAdminsEnum adminsEnumTemp = values[i];
            if (adminsEnumTemp.toString().startsWith("SEX")) {
                if (adminsEnumTemp.getStatus() == this.sex) {
                    this.sexStr = adminsEnumTemp.getName();
                }
            }
        }
        return sexStr;
    }
}